//
//  GoodsTableViewCell.swift
//  Pods
//
//  Created by eme on 2017/3/31.
//
//

import UIKit
import UtilCore
import RickonCore
import BrandonCore

class GoodsTableViewCell: UITableViewCell {
    
    @IBOutlet weak var goodsImageView: UIImageView!  //商品图片
    
    @IBOutlet weak var nameLabel: UILabel!           //商品名称
    
    @IBOutlet weak var storeNameLabel: UILabel!      //店铺名称
    
    @IBOutlet weak var priceLabel: UILabel!          //价格Label
    
    @IBOutlet weak var addJHD_Button: UIButton!      //加入进货单按钮
    
    @IBOutlet weak var jingLabel: UILabel!           //"进"字Label
    
    @IBOutlet weak var clicked_imageView: UIImageView!
    
    @IBOutlet weak var imageViewWithLeft: NSLayoutConstraint!
    
    @IBOutlet weak var Goods_StatusImageView: UIImageView!
    
    @IBOutlet weak var IconImageView: UIImageView!
    @IBOutlet weak var LineView: UIView!
    
    var gooditem:CollectGoodsListModel?{
        didSet{
            if let model = gooditem{
                if model.istimeby == "1"{
                    self.nameLabel.setReplaceText(text: AppConfig.timelimit + model.pdname, replace: AppConfig.timelimit, value: Theme.sansa.collect.xsgtextColor)
                    self.addJHD_Button.isEnabled = false
                }else{
                    self.nameLabel.text = model.pdname
                    self.addJHD_Button.isEnabled = true
                }
                
                if model.pdstate != "3"{
                    self.Goods_StatusImageView.image = UIImage(named: "failure", in: SansaCore.bundle, compatibleWith: nil)
                    self.addJHD_Button.isEnabled = false
                }else{
                    if model.stock == "0"{
                        self.Goods_StatusImageView.image = UIImage(named: "sellout", in: SansaCore.bundle, compatibleWith: nil)
                        self.addJHD_Button.isEnabled = false
                    }else{
                        self.Goods_StatusImageView.image = UIImage(named: "")
                        if model.istimeby == "1"{
                            self.addJHD_Button.isEnabled = false
                        }else{
                            self.addJHD_Button.isEnabled = true
                        }
                    }
                }
                self.priceLabel.text = AppData.getFinalShowPrice(jinPrice: model.minshprice, lingPrice: model.bdprice).getPriceStr()
                self.IconImageView.image = UIImage(named: AppData.setJINorLinIcon(), in: SansaCore.bundle, compatibleWith: nil)
                self.storeNameLabel.text = model.brname
            }
        }
    }
    var isEditor:Bool?{
        didSet{
            if isEditor == false{
                
                gooditem!.isclicked = 0
                self.clicked_imageView.isHidden = true
                self.addJHD_Button.isHidden = false
                self.imageViewWithLeft.constant = -17
                
            }else{
                
                self.clicked_imageView.isHidden = false
                self.addJHD_Button.isHidden = true
                self.imageViewWithLeft.constant = 6
                
                
                if gooditem!.isclicked == 0{
                    self.clicked_imageView.image = UIImage(named: "not clicked", in: SansaCore.bundle, compatibleWith: nil)
                }else{
                    self.clicked_imageView.image = UIImage(named: "The selected", in: SansaCore.bundle, compatibleWith: nil)
                }
            }
        }
    }
    

    override func awakeFromNib() {
        super.awakeFromNib()
        LineView.backgroundColor = Theme.v.separate_Line
        nameLabel.normal_fontSize(14)
        storeNameLabel.normal_fontSize(13)
        priceLabel.bold_fontSize(14)
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
